<?php /* Template Name: Homepage */ ?>

<?php get_header(); ?>
            
<?php $canon_options_slider = get_option('canon_options_slider'); ?>
<?php $canon_options_hp = get_option('canon_options_hp'); ?>


        <!-- SLIDER MASTHEAD -->

        <?php 

            if (empty($canon_options_slider['slides'])) {

                //code here for when no slides

            } elseif (count($canon_options_slider['slides']) === 1) {
            ?>

                <div class="wrapper sliderWrapper">
                    <div class="column cta third <?php echo $canon_options_slider['slides'][0]['text_alignment']; ?>">
                        <?php echo $canon_options_slider['slides'][0]['text']; ?>
                    </div>
                </div>

            <?php

            } else {

                echo '<ul class="slides-container">';  

                for ($i = 0; $i < count($canon_options_slider['slides']); $i++) {  

                ?>

                    <li>
                        <img src="<?php echo $canon_options_slider['slides'][$i]['image_url']; ?>" class="slide-img">
                        <div class="wrapper">
                            <div class="column cta third <?php echo $canon_options_slider['slides'][$i]['text_alignment']; ?>">
                                <?php echo $canon_options_slider['slides'][$i]['text']; ?>
                            </div>
                        </div>
                    </li>

                <?php


                } //end fori

                ?>

                </ul>

                <nav class="slides-navigation">
                    <a href="#" class="next">s</a>
                    <a href="#" class="prev">S</a>
                </nav>

            <?php

            }

        ?>
            
              

              
    </div>
    <!-- END HEADER-CONTAINER -->





    <!-- Start Main Body -->
    <div class="main-container">
        <div class="main wrapper clearfix">

        	<!-- Start Main Content -->
            <div class="main-content full">
            	<div class="clearfix">


                    <!-- HOOK: BELOW SLIDER -->
                    <?php get_template_part('inc/hooks/hook_below_slider'); ?>


                    <!-- FEATURES -->
                    <?php 

                        if ($canon_options_hp['show_features'] == "checked") {

                            for ($n = 0; $n < count($canon_options_hp['features']); $n++) {  

                                //set vars
                                $num_shown_in_row = 0;

                                //get num to show in this row
                                $num_to_show_in_row = 0;
                                foreach ($canon_options_hp['features'][$n] as $key => $value) {
                                    if ($value['show'] == 'checked') $num_to_show_in_row++;
                                }

                                //set classes
                                $class_base = "centered";

                                $class_size ="";
                                switch ($num_to_show_in_row) {
                                    case 1:
                                        $class_size =" full";
                                        break;
                                    case 2:
                                        $class_size =" half";
                                        break;
                                    case 3:
                                        $class_size =" third";
                                        break;
                                    case 4:
                                        $class_size =" fourth";
                                        break;
                                    case 5:
                                        $class_size =" fifth";
                                        break;
                                    default:
                                        $class_size =" third";
                                        break;
                                }

                                //output
                                echo '<div class="clearfix">';

                                for ($i = 0; $i < count($canon_options_hp['features'][$n]); $i++) {  

                                    if ($canon_options_hp['features'][$n][$i]['show'] == "checked") {
                                        $num_shown_in_row++;

                                        //set last class
                                        $class_last ="";
                                        if ($num_shown_in_row == $num_to_show_in_row) { $class_last = " last"; }

                                        //set final class
                                        $class_final = $class_base . $class_size . $class_last;

                                        //failsafe empty icon_url
                                        if (!isset($canon_options_hp['features'][$n][$i]['icon_url'])) { $canon_options_hp['features'][$n][$i]['icon_url'] = ""; }

                                        // var_dump($canon_options_hp['features']);

                                        ?>

                                            <div class="<?php echo $class_final; ?>">

                                                <!-- ICON -->
                                                <?php 

                                                    if (!empty($canon_options_hp['features'][$n][$i]['icon_url'])) {
                                                        printf('<p class="feature-icon"><img src="%s" alt="icon" /></p>', esc_url($canon_options_hp['features'][$n][$i]['icon_url']));           
                                                    } else {
                                                        printf('<p class="feature-icon"><i class="fa %s"></i></p>', esc_attr($canon_options_hp['features'][$n][$i]['font_awesome_icon']));           
                                                    }

                                                ?>

                                                <h3><?php echo $canon_options_hp['features'][$n][$i]['title']; ?></h3>
                                                <p><?php echo do_shortcode($canon_options_hp['features'][$n][$i]['text']); ?></p>

                                            </div>

                                        <?php

                                    } // end if show checked

                                } // end fori

                                echo '</div><hr/>';

                            } // end forn

                        } // end if show_features checked

                    ?>

                	
                    <!-- HOOK: BELOW FEATURES -->
                    <?php get_template_part('inc/hooks/hook_below_features'); ?>


                    <!-- QUOTES-->

                    <?php 

                        if ($canon_options_hp['use_hp_quotes'] == "checked") {

                            if ($canon_options_hp['hp_quotes_style'] == 'tweets') {
                            ?>
                                <div id='hp_twitter_widget'>
                                    <?php 
                                        if (!empty($canon_options_hp['hp_twitter_widget_code'])) {
                                            echo $canon_options_hp['hp_twitter_widget_code']; 
                                        } else {
                                            echo "<i>Please insert your Twitter widget code!</i>";
                                        }
                                    ?>

                                </div>


                                <div id="hp_tweets" class="flexslider-quote tweets">
                                    <ul class="slides">
                                    </ul>
                                </div>
                                
                            <?php    
                            } elseif ($canon_options_hp['hp_quotes_style'] == 'manual') {
                            ?>
                                <div class="flexslider-quote<?php if ($canon_options_hp['manual_quotes_as_tweets'] == "checked") echo " tweets"; ?>">
                                  <ul class="slides">
                                    <?php 
                                        for ($i = 0; $i < count($canon_options_hp['hp_quotes']); $i++) {  
                                        ?>
                                            <li><blockquote><?php echo $canon_options_hp['hp_quotes'][$i][0]; ?><cite>- <?php echo $canon_options_hp['hp_quotes'][$i][1]; ?></cite> </blockquote></li>
                                        <?php
                                        }

                                    ?>
                                  </ul>
                                </div>
                            <?php

                            } // end if tweets or manual

                        } // end if use_hp_quotes checked

                    ?>


                    <!-- HOOK: ABOVE FOOTER -->
                    <?php get_template_part('inc/hooks/hook_above_footer'); ?>
                        
                        
                                                                       
                </div>    
            </div>
            <!-- Finish Main Content -->

    	</div> 
    </div> 
    <!-- END #main-container -->


<?php get_footer(); ?>
